#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
class Solution {
public:
    int largestOverlap(const vector<vector<int>>& A, const vector<vector<int>>& B) {
        int ans = 0;
        vector<int> flat_a, flat_b;
        unordered_map<int, int> distance_count;
        for (int r = 0; r < A.size(); ++r) {
            for (int c = 0; c < B.size(); ++c) {
                if (A[r][c]) flat_a.push_back(flat(r, c));
                if (B[r][c]) flat_b.push_back(flat(r, c));
            }
        }
        for (const auto& a : flat_a) {
            for (const auto& b : flat_b) {
                ++distance_count[a - b];
            }
        }
        for (const auto& c : distance_count)
            ans = max(ans, c.second);
        return ans;
    }
private:
    static inline int flat(const int r, const int c) { return (r << 6) + c; }
};
int main()
{
	return 0;
}